package tw.com.softleader.gary.movie.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import tw.com.softleader.gary.movie.model.MovieModel;
import tw.com.softleader.gary.movie.service.MovieService;
import tw.com.softleader.gary.movie.service.impl.MovieServiceImpl;

public class MovieDelServlet extends HttpServlet {

	public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

		// getting movieService from ServletContext
		MovieService movieService =  (MovieService) this.getServletContext().getAttribute("movieService");
		if(movieService == null) {
			 movieService = new MovieServiceImpl();
			 this.getServletContext().setAttribute("movieService", movieService);
		}
		
		
		String id = request.getParameter("id");
		
		MovieModel movie = new MovieModel();
		movie.setId(new Long(id));
		
		
		try {
			
			
			
			movieService.delete(movie);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		response.sendRedirect("MovieListServlet");
	}
}
